package com.orderSystem;
import com.databaseManager.*;
import javafx.beans.binding.ObjectExpression;

import java.util.Queue;
import java.util.Random;

public class QueueHandle {
    static int proQueuelimit = 100;
    public String addproQueue(Patient patient) {                   // 加入专家预约队列
	try {
		DatabaseFunc df = new DatabaseFunc();
	    QueueInstance object = QueueInstance.getInstance();
	    if (object.getProList().size()>= proQueuelimit)
		return "2";
	    object.inQueue(4,patient);
	    return "1";
	} catch (Exception e1) {
	    // TODO Auto-generated catch block
	    e1.printStackTrace();
	    return "0";
	}
    }

    public String adddepQueue(Patient patient) {                    // 加入科室预约队列
	try {
		QueueInstance object = QueueInstance.getInstance();
	    object.inQueue(3,patient);
	    return "1";
	} catch (Exception e1) {
	    // TODO Auto-generated catch block
	    e1.printStackTrace();
	    return "0";
	}
    }

    public String addpriorityDepQueue(Patient patient) {                    // 加入科室优先队列
	try {
		QueueInstance object = QueueInstance.getInstance();
	    object.inQueue(6,patient);
	    return "1";
	} catch (Exception e1) {
	    // TODO Auto-generated catch block
	    e1.printStackTrace();
	    return "0";
	}
    }

    public String addpriorityProQueue(Patient patient) {                                 // 加入专家优先队列
	try {
	    QueueInstance object = QueueInstance.getInstance();
	    object.inQueue(5,patient);
	    return "1";
	} catch (Exception e1) {
	    // TODO Auto-generated catch block
	    e1.printStackTrace();
	    return "0";
	}
    }


    public String addnormalProQueue(Patient patient) {             // 普通挂号，排队时加入普通专家队列
	try {
	    QueueInstance object = QueueInstance.getInstance();
		object.outQueue(1);
	    return "1";
	} catch (Exception e1) {
	    // TODO Auto-generated catch block
	    e1.printStackTrace();
	    return "0";
	}
    }
    public String addnormalDepQueue(Patient patient) {                   // 普通挂号，排队时加入普通科室队列
	try {
	    QueueInstance object = QueueInstance.getInstance();
		object.outQueue(2);
		return "1";
	} catch (Exception e1) {
	    // TODO Auto-generated catch block
	    e1.printStackTrace();
	    return "0";
	}
    }
	public String removeproList(Patient patient) {                   // 退出专家预约队列
		try {
			DatabaseFunc df = new DatabaseFunc();
			QueueInstance object = QueueInstance.getInstance();
			object.outList(4,patient);
			return "1";
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return "0";
		}
	}

	public String removedepList(Patient patient) {                    // 退出科室预约队列
		try {
			QueueInstance object = QueueInstance.getInstance();
			object.outList(3,patient);
			return "1";
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return "0";
		}
	}

	public Patient pollpriorityDepQueue() {                    // 退出科室优先队列
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.outQueue(6);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}

	}

	public Patient pollpriorityProQueue() {                                 // 退出专家优先队列
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.outQueue(5);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
	}

	public Patient pollnormalProQueue() {                    // 普通挂号，排队时退出普通专家队列
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.outQueue(1);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
	}
	public Patient pollnormalDepQueue() {                   // 普通挂号，排队时退出普通科室队列
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.outQueue(2);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
	}
	public boolean IsEmptypriorityProQueue() {
		try {
			QueueInstance object = QueueInstance.getInstance();
			if (object.getPriorityProQueue()!= null);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		}
		return true;
	}
	public boolean IsEmptypriorityDepQueue() {
		try {
			QueueInstance object = QueueInstance.getInstance();
			if (object.getPriorityDepQueue()!= null);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		}
		return true;
	}
	public Patient getPeekPriorityDepQueueNode(){
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.getPriorityDepQueue().peek();
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
	}
	public Patient getPeekPriorityProQueueNode(){
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.getPriorityProQueue().peek();
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
	}
	public Patient getPeekNormalDepQueueNode(){
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.getNormalDepQueue().peek();
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
	}
	public Patient getPeekNormalProQueueNode(){
		try {
			QueueInstance object = QueueInstance.getInstance();
			return object.getNormalProQueue().peek();
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
	}
	public void inName_priorityDepQueue(Patient patient,String string){
    	try
		{
			QueueInstance object = QueueInstance.getInstance();
			object.inMap(7,patient,string);
		}catch(Exception e){
    		e.printStackTrace();
		}
	}
	public void inName_priorityProQueue(Patient patient,String string){
		try
		{
			QueueInstance object = QueueInstance.getInstance();
			object.inMap(8,patient,string);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void inName_normalDepQueue(Patient patient,String string){
		try
		{
			QueueInstance object = QueueInstance.getInstance();
			object.inMap(9,patient,string);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void inName_normalProQueue(Patient patient,String string){
		try
		{
			QueueInstance object = QueueInstance.getInstance();
			object.inMap(10,patient,string);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public String getsid(Patient patient) {
		try {
			QueueInstance object = QueueInstance.getInstance();
			String a=object.getName_normalProQueue().get(patient);
			String b=object.getName_normalDepQueue().get(patient);
			String c=object.getName_priorityProQueue().get(patient);
			String d=object.getName_priorityDepQueue().get(patient);
			if(a!=null) return a;
			if(b!=null) return b;
			if(c!=null) return c;
			if(d!=null) return d;
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}
		return null;
	}
}
